# -*- encoding:utf-8 -*-

from taobao.request import TaobaoRequest

class ItemsSearchRequest(TaobaoRequest):
    """TOP API: taobao.items.search"""

    # 需要返回的商品对象字段
    fields  = str()
    # 搜索字段
    q       = str()
    # 卖家昵称列表
    nicks   = str()
    # 商品所属类目Id
    cid     = str()
    # 商品属性
    props   = str()
    # product_id
    # 可以根据产品Id搜索属于这个spu的商品
    productId   = str()
    # start_price, 商品最低价格。单位:元。正整数，取值范围:0-100000000。
    startPrice  = str()
    # end_price, 商品最高价格。单位:元。正整数，取值范围:0-100000000。 
    endPrice    = str()
    # page_no, 页码。取值范围:大于零的整数; 默认值:1
    pageNo      = int(1)
    # page_size, 每页条数。取值范围:大于零的整数;最大值:200;默认值:40。 
    pageSize    = int()
    # order_by 排序方式 
    orderBy     = str()
    # ww_status 旺旺在线状态 
    wwStatus    = bool()
    # post_free 免运费
    postFree    = bool()
    # location.state 
    state       = str()
    city        = str()
    # is_3D, 是否是3D淘宝的商品,置为false或为空表示不对是否3D商品进行判断 
    is3D        = bool()
    
    def __init__(self, *args, **kwargs):
        pass

    def setFields(self, fields):
        self.fields = fields

    def setQ(self, q):
        self.q = q

    def setNicks(self, nicks):
        self.nicks = nicks

    def setCid(self, cid):
        self.cid = cid

    def getApiName(self):
        return "taobao.items.search"

    def getTextParams(self):

        params = {}
        # setup text params
        params['fields']         = self.fields
        params['q']              = self.q
        params['nicks']          = self.nicks
        params['cid']            = self.cid
        params['props']          = self.props
        params['product_id']     = self.productId
        params['start_price']    = self.startPrice
        params['end_price']      = self.endPrice
        params['page_no']        = self.pageNo
        params['page_size']      = self.pageSize
        params['order_by']       = self.orderBy
        params['ww_status']      = self.wwStatus
        params['post_free']      = self.postFree
        params['location.state'] = self.state
        params['location.city '] = self.city
        params['is_3D']          = self.is3D

        return params
